package com.yangluyao.jsr303.hibernate.validator.model;

import com.yangluyao.jsr303.hibernate.validator.valid.SaveValidated;
import com.yangluyao.jsr303.hibernate.validator.valid.UpdateValidated;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * @author YLY
 * @ClassName User
 * @Date 2020/7/30
 * @Version 1.0.2
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
public class User {

    @NotNull(message = "id不能为空",groups = {UpdateValidated.class})
    private Long id;

    @NotNull(message = "姓名不能为空",groups = {SaveValidated.class, UpdateValidated.class})
    private String name;

    @NotNull(message = "新增年龄不能为空",groups = {SaveValidated.class})
    @NotNull(message = "修改年龄不能为空",groups = {UpdateValidated.class})
    @Max(value = 127, message = "年龄不能大于127")
    @Min(value = 0, message = "年龄不能小于0")
    private Integer age;
}
